<script setup>
import {ref} from "vue";
import request5151 from "../../../utils/request5151.js";
import {ElMessage} from "element-plus";
import {useProgressStore} from "../../../stores/progressStore.js";
import {useRouter} from "vue-router";
const router = useRouter()
const progressStore = useProgressStore()
const getDate = ref('')
const IsGet = ref(false)
//判断是否领取
const getIsGet = () => {
  if (!sessionStorage.getItem('snumber')) {
    ElMessage.error("获取信息失败")
    return
  }
  request5151({
    url: '/goodsget/IsGet',
    method: 'get',
    params: {
      sNumber: sessionStorage.getItem('snumber')
    }
  }).then((res) => {
    if (res.data.code === 200) {
      IsGet.value = false
    } else {
      IsGet.value = true
      getDate.value = res.data.message
    }
  }).catch((err) => {
    ElMessage.error("error")
  })
}
getIsGet()
//领取
const getAll = () => {
  if (!sessionStorage.getItem('snumber')) {
    ElMessage.error("获取信息失败")
    return
  }
  request5151({
    url: '/goodsget/addGoodsGet',
    method: 'post',
    params: {
      sNumber: sessionStorage.getItem('snumber')
    }
  }).then((res) => {
    if (res.data.code === 200) {
      ElMessage.success("领取成功")
      progressStore.setProgressG(1)
      getIsGet()
    } else {
      ElMessage.error(res.data.message)
    }
  }).catch((err) => {
    ElMessage.error("error")
  })
}
</script>

<template>
  <div class="goodsGet_All">
    <div class="goodsGet_main_left">
      <el-card class="goods">
        <img src="../../../assets/welcome/goods.png" height="200" width="265"/>
        <h5>编号: 1001</h5>
        <h4>名称: 被子,床单,宿舍用品</h4>
        <h4>类型: 宿舍用品</h4>
      </el-card>
      <el-card class="goods">
        <img src="../../../assets/welcome/goods1.jpg" height="200" width="265"/>
        <h5>编号: 1002</h5>
        <h4>名称: 脸盆,牙刷,牙膏</h4>
        <h4>类型: 洗漱用品</h4>
      </el-card>
      <el-button class="getGoodsButton" type="success" v-if="IsGet===false"
                 @click="getAll">全部领取
      </el-button>
      <el-button class="getGoodsButton" type="success" v-else>已领取</el-button>
      <el-button class="getGoodsButton" type="success" @click="router.push('/reportAll/toPay')">我不需要</el-button>
    </div>
    <div class="goodsGet_main_right">
      <h2>领取情况</h2>
      <hr>
      <h4>领取时间:{{ getDate }}</h4>
    </div>
  </div>
</template>

<style scoped>
.goodsGet_main_right h4 {
  margin-top: 30px;
}

.goods {
  width: 300px;
  height: 400px;
}

.goodsGet_main_left {
  width: 60%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 30px;
  padding-right: 30px;
}

.goodsGet_main_right {
  text-align: center;
  width: 40%;
  background-color: #99a9bf;
}

.goodsGet_All {
  width: 100%;
  margin: 20px auto;
  display: flex;
  justify-content: space-between;
  height: 400px;
}
</style>
